package sample.mybatis.web;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import sample.mybatis.domain.User;
import sample.mybatis.jpa.repository.UserRepository;
import sample.mybatis.service.UserService;

import java.util.ArrayList;
import java.util.List;


/**
 * User的控制器，用于显示同时查询2个数据库的结果
 *
 * @author 小翼
 * @version 1.0.0
 */

@RestController
public class UserController {

	@Autowired
	UserService userService;
	@Autowired
	UserRepository userRepository;

	/*@RequestMapping(value = "/user", method = RequestMethod.GET)
	public List<User> readUserInfo(){
		List<User> list = new ArrayList();
		list.add(userService.readUserByUsername("lxy"));
		list.addAll(userRepository.findAll());
		return list;
	}*/

	@RequestMapping(value = "/user/{uname}", method = RequestMethod.GET)
	public List<User> chooseUserInfo(@PathVariable String uname){
		List<User> list = new ArrayList();
		list.add(userService.readUserByUsername(uname));
//		list.addAll(userRepository.findAll());
		return list;
	}

	@RequestMapping(value = "/userf/{uname}", method = RequestMethod.GET)
	public List<User> chooseUserFull(@PathVariable String uname){
		List<User> list = new ArrayList();
		list.add(userService.readUserFullByUsername(uname));
		return list;
	}

	@RequestMapping(value = "/users", method = RequestMethod.GET)
	public List<User> chooseUserInfo(){
		List<User> list = new ArrayList();
//		list.add(userService.readAllByUsername());
		list.addAll(userRepository.findAll());
		return list;
	}

	@RequestMapping(value = "/")
	public String defaultPage(){
		return "Default Page";
	}

	@RequestMapping(value = "/frankie")
	public String frankiePage(){
		return "Frankie Yang Page";
	}

	@ExceptionHandler
	public String exptHndlr(Exception e){
		return "some Error occur!" + e.toString();
	}



	ProceedingJoinPoint prcsJoinPoint;


	ControllerAdvice ctrlAdvc;
	RestControllerAdvice restCtrlAdvc;
	ResponseBodyAdvice respBodyAdvc;



}
